<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace XWAM\Model;

/**
 * Description of SessionFilterModel
 *
 * @author SoChishun
 */
class SessionFilterModel {

    protected static $name = 'login_error_count';

    // 2017-3-13
    public static function setLoginCount() {
        $data = session(self::$name);
        if (is_array($data)) {
            $n = $data['count'];
        } else {
            $n = 0;
        }
        $n++;
        session(self::$name, array('count' => $n, 'time' => strtotime('5 min')));
    }

    public static function getLoginStatus() {
        $data = session(self::$name);
        if ($data && $data['count'] > 5) {
            if ($data['time'] > time()) {
                return false;
            }
            session(self::$name, null); // 清空
        }
        return true;
    }

}
